package cn.com.dycc.party_dues.remind.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.party_dues.remind.entity.Remind;
import cn.com.dycc.party_dues.remind.param.RemindParam;
import cn.com.dycc.party_dues.remind.service.RemindNotFoundException;
import cn.com.dycc.party_dues.remind.service.RemindService;
import cn.com.dycc.util.JsonObjectResult;


/**
 * 
 * Description: 党费自动提醒的设置管理控制层
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年11月15日 下午3:54:20.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/remind")
public class RemindController extends BaseController{
	
	@Resource
	private RemindService remindService;
	
	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addRemind(HttpServletRequest req,Remind remind){
		int n = remindService.addRemind(req, remind);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deleteRemind(HttpServletRequest req,String remind_id){
		int n = remindService.deleteRemind(req, remind_id);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonObjectResult updateRemind(HttpServletRequest req,Remind remind){
		int n = remindService.updateRemind(req, remind);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/find.do")
	@ResponseBody
	public JsonObjectResult findRemind(HttpServletRequest req,String remind_id){
		Remind remind = remindService.findRemindById(req, remind_id);
		return new JsonObjectResult(remind);
	}
	
	@RequestMapping("/param.do")
	@ResponseBody
	public JsonObjectResult paramRemind(HttpServletRequest req,RemindParam param){
		List<Remind> list = remindService.findRemindByParam(req,param);
		String count = remindService.countRemindByParam(req,param);
		return new JsonObjectResult(count,list);
	}
	
	@ExceptionHandler(RemindNotFoundException.class)
	@ResponseBody
	public JsonObjectResult remindException(RemindNotFoundException e){
		e.printStackTrace();
		return new JsonObjectResult(1020,e);
	}
}
